import { routerRedux } from 'dva/router'
import {login} from '../services/users'
export default {
  namespace: 'login',

  state: {
    USER_NAME:'',
    USER_PSW:'',
  },
  reducers: {
    save(state, { payload: { USER_NAME, USER_PSW } }) {
      return { ...state, USER_NAME, USER_PSW };
    },
  },

  effects: {
    * login ({
               payload,
             }, { put, call, select }) {
      // let m = logins(payload);
      // m.then((result)=> {
      //   console.log(m);
      // });
      const data = yield call(login, payload);

      //const { locationQuery } = yield select(_ => _.app);
      // console.log(data);
      yield put({
        type: 'save',
        payload:payload,
      });
      yield put(routerRedux.push('/IndexPage'));
      // if (data.success) {
      //   const { from } = locationQuery
      //   yield put({ type: 'app/query' })
      //   if (from && from !== '/login') {
      //     yield put(routerRedux.push(from))
      //   } else {
      //     yield put(routerRedux.push('/IndexPage'))
      //   }
      // } else {
      //   throw data
      // }
    },
  },

}
